package com.gem.netty.hanlder;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.handler.timeout.IdleStateHandler;

/**
 * Author: Xhy
 * CreateTime: 2022-09-20 13:40
 */
public class ServerHandler extends ChannelInitializer<SocketChannel> {


    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        WebSocketHandler WEB_SOCKET_HANDLER = new WebSocketHandler();
        // 解决粘包半包问题
//        ch.pipeline().addLast(new ProcotolFrameDecoder());
        ch.pipeline().addLast(new HttpServerCodec());
        ch.pipeline().addLast(new ChunkedWriteHandler());
        ch.pipeline().addLast(new HttpObjectAggregator(8192));
        ch.pipeline().addLast(new WebSocketServerProtocolHandler("/ws","WebSocket",true,65536*10));
        // join room
        ch.pipeline().addLast(WEB_SOCKET_HANDLER);


    }
}
